define(['template','jquery'],(template)=>{
	class Header{
		constructor(){
			this.loadHTML().then(()=>{
				this.getTabs()
				this.calcCarCount()
				// this.select()
			})
		}
		loadHTML(){
			return new Promise(resolve => {
				// 使用jquery的load方法去加载header.html
				$('header').load('/html/modules/header.html',resolve)
			})
		}
		// select(){
		// 	$('#user').mouseenter(function(){
		// 		$('#box1').css("display","block")
		// 	})
		// 	$('#box1').mouseleave(function(){
		// 		$('#box1').css("display","none")
		// 	})
		// }
		
		getTabs(){
			//从熊猫优选的接口获得 头部导航的分类
			$.get('http://www.xiongmaoyouxuan.com/api/tabs',resp=>{
				if(resp.code===200){
					const{list}=resp.data
					$('#tabList').html(template('tabListTemplate',{list:list.slice(1,8)}))
				}
			})
		}
		calcCarCount(){
			let count=0
			let car=localStorage.getItem('car')
			if(car){
				car=JSON.parse(car)
				count=car.reduce((num,shop)=>{
					return num+shop.count
				},0)
			}
			$('#shopnum').html(count)
			$('#shopcar').html(count)
		}
	}
	return new Header()
})